package iscript.uiFramework.components.menu 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import iscript.uiFramework.components.InteractiveUIComponent;
	import iscript.uiFramework.components.spacer.BaseSpacer;
	import iscript.uiFramework.components.text.Label;
	import iscript.uiFramework.components.UIComponent;
	import iscript.uiFramework.UIFramework;
	import iscript.uiFramework.util.Scale9GridBitmap;

	
	public class ToolStripItem extends InteractiveUIComponent
	{
		
		/**
		 * 菜单子项高度
		 */
		internal static const SpaceHeight:Number = 22;
		
		/**
		 * 缩进Pixel
		 */
		internal static const blockindent:Number = 33;
		
		internal static const minWidth:Number = 135;
		
		/**
		 * 占位符
		 */
		 protected var _spacer:BaseSpacer;
		 /**
		  * 18*18 mini icon
		  */
		 private var _icon:BitmapData;
		 protected  var _iconBitmap:Bitmap;
		 private var _hoverBitmapdata:BitmapData 
		 protected var _hoverScale9GridBitmap:Scale9GridBitmap;
		 private var _data:Object;

		 
		public function ToolStripItem() 
		{
			super ();
		}
		
		override protected function initialize():void 
		{
			_spacer = new BaseSpacer(true);
			_spacer.width = minWidth;
			_spacer.height =  SpaceHeight;
			_spacer.render(this);			
			
			_hoverBitmapdata =  UIFramework.resource.getBitmapData ("GameLite.UIComponent." + this.theme + ".MenuPanelItem.Hover");
			var rect:Rectangle =  UIFramework.resource.getElementRectangle ("Menu", "MenuPanelItemHover");
			_hoverScale9GridBitmap = new Scale9GridBitmap (_hoverBitmapdata, rect);
			_hoverScale9GridBitmap.x = 1;
			_hoverScale9GridBitmap.width = _spacer.width-2;
			_hoverScale9GridBitmap.visible = false;
			addChild (_hoverScale9GridBitmap);
			 
			_icon = new BitmapData (18, 18, true, 0xFFFFFF);
			_iconBitmap = new Bitmap (_icon);
			_iconBitmap.width = 18;
			_iconBitmap.height = 18;
			_iconBitmap.x = 4;	
			_iconBitmap.y= (_spacer.height-_iconBitmap.height)/2
			addChild (_iconBitmap);
			
			 
		    addEventListener(MouseEvent.MOUSE_OVER,TextHoverHandler)
		    addEventListener(MouseEvent.MOUSE_OUT,TextOutHandler) 
			super.initialize();
		}
		
		override public function set width(value:Number):void 
		{
			if (value < minWidth) value = minWidth;
			super.width = value;
			_spacer.width = value;
			_hoverScale9GridBitmap.width = _spacer.width-2;
		}
		
		private function TextOutHandler(e:*):void 
		{
			if(isActive)
			_hoverScale9GridBitmap.visible = false;
		}
		
		private function TextHoverHandler(e:*):void 
		{
			if(isActive)
			_hoverScale9GridBitmap.visible = true;
		}
		
		///GET SET/////////////////////////////////////////////////
 		public function get icon():BitmapData 
		{
			return _icon;
		}
		
		public function set icon(value:BitmapData):void 
		{
			_icon = value;
			_iconBitmap.bitmapData = value;
			_iconBitmap.width = 18;
			_iconBitmap.height = 18;
		}
		
		
		override public function set disabled(value:Boolean):void 
		{
			super.disabled = value;
		}
		
		
		/**
		 * 自定义数据
		 */
		public function get data():Object 
		{
			return _data;
		}
		
		public function set data(value:Object):void 
		{
			_data = value;
		}
		
		
		
		
		
	}

}